home *** CD-ROM | disk | FTP | other *** search
/ Macwelt 1 / Macwelt DVD 1.toast / Web-Publishing / HTML-Editoren / Alpha ƒ / Mode Examples / modeExamplesScript.tcl < prev    next >
Encoding:
Text File  |  2000-10-30  |  9.9 KB  |  261 lines

  1. ## -*-Tcl-*-
  2.  # ==========================================================================
  3.  #  Mode Examples - a Help package for Alpha
  4.  # 
  5.  #  FILE: "Mode Examples Script.tcl"
  6.  # 
  7.  #                                    version: 2.0.5
  8.  #                                    created: 05/13/00 {02:43:47 pm} 
  9.  #                                last update: 08/22/00 {03:25:05 pm} 
  10.  #  Description: 
  11.  #  
  12.  #  Script which supports Mode Example hyperlinks.
  13.  #  
  14.  #  -------------------------------------------------------------------------
  15.  #  Usage:
  16.  #  
  17.  #  Include the following hypertext to link to a mode example --
  18.  #  
  19.  #    set f  "filename.sfx" ; 
  20.  #    source [file join $HOME "Mode Examples" "Mode Examples Script.tcl"]
  21.  #  
  22.  #  Or see the "Help Files Help" file for information on creating
  23.  #  hyperlinks with auto-marking help files.  Additional "Special Cases"
  24.  #  can be easily added to this script -- please send any requests to the
  25.  #  author.
  26.  #  
  27.  #  -------------------------------------------------------------------------
  28.  # 
  29.  #  Author: Craig Barton Upright
  30.  #  E-mail: <cupright@princeton.edu>
  31.  #    mail: Princeton University,  Department of Sociology
  32.  #          Princeton, New Jersey  08544
  33.  #     www: <http://www.princeton.edu/~cupright>
  34.  #  
  35.  # Copyright (c) 2000  Craig Barton Upright
  36.  # 
  37.  # This program is free software; you can redistribute it and/or modify
  38.  # it under the terms of the GNU General Public License as published by
  39.  # the Free Software Foundation; either version 2 of the License, or
  40.  # (at your option) any later version.
  41.  # 
  42.  # This program is distributed in the hope that it will be useful,
  43.  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  44.  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  45.  # GNU General Public License for more details.
  46.  # 
  47.  # You should have received a copy of the GNU General Public License
  48.  # along with this program; if not, write to the Free Software
  49.  # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  50.  # 
  51.  # ==========================================================================
  52.  # 
  53.  # ◊◊◊◊ version history ◊◊◊◊ #
  54.  # 
  55.  # 1.0   (03/00)   First version of Mode Examples.
  56.  # 1.1   (04/00)   Additional examples added.
  57.  # 1.2   (04/00)   Additional examples added, including Alpha specific modes.
  58.  # 1.3   (05/00)   Additional examples added.
  59.  #                 Alpha specific modes in separate section.
  60.  # 1.4   (06/00)   Additional examples added.
  61.  #                 Reformatted Help file, using the auto-marking procs.
  62.  #                 This is the last version that will be 7.3 compatible, and
  63.  #                   won't be updated after the public release of 7.4.
  64.  # 2.0   (06/00)   Reformatted Help file, using the auto-marking procs.
  65.  # 2.0.1 (07/00)   Additional examples added.
  66.  #                 Amended the "technical notes" section in help file.
  67.  # 2.0.2 (07/00)   Minor bug fix to script.
  68.  #                 Changed the "technical notes" section in help file, which
  69.  #                   now refers to the new "Help Files Help" file.
  70.  # 2.0.3 (08/00)   Minor bug fix to script.
  71.  # 2.0.4 (08/00)   Added Filters, Manip Cols tutorials.
  72.  # 2.0.5 (08/00)   Turned the script into a proc, which is then called.
  73.  # 
  74.  ##
  75.  
  76.  
  77. namespace eval examples {}
  78.  
  79. # First, bind control-?  and control-<help> to open any available help for
  80. # the mode.  These bindings will endure for the rest of the Alpha session.
  81.  
  82. Bind 0x2c <sz>  {examples::modeHelp}
  83. Bind 0x2c <z>   {examples::modeHelp}
  84. Bind help <z>   {examples::modeHelp}
  85.  
  86. proc examples::modeHelp {} {
  87.     global mode
  88.     package::helpFile $mode
  89. }
  90.  
  91. # Then find out what to do with the "file" f, defined in the hyperlink.
  92. # Define the proc first, then call it below.
  93.  
  94. proc examples::modeExamplesScriptProc {{f ""}} {
  95.     
  96.     global HOME
  97.     
  98.     # Example files must be of the form "<something>-Example", with an
  99.     # optional suffix.  If the hyperlink looks like "<something> Example",
  100.     # with the optional suffix, it will open in a shell window.
  101.     regsub -all { } $f {-} f2
  102.     
  103.     if {$f == ""} {
  104.         # This script wants to assume that "f" has been defined.
  105.         beep
  106.         message "Sorry, no file has been defined"
  107.         return
  108.     } elseif {$f == $f2} {
  109.         # Open as a read-only file
  110.         edit -r -c [file join $HOME "Mode Examples" $f]
  111.         return
  112.     }
  113.     # Now we find out what to do with "f".
  114.     if {$f == "Browser Example"} {
  115.         # Deal with special cases first, starting with Browser.
  116.         # Additional special cases can be easily added here.
  117.         # Please keep them in alphabetical order.
  118.         browseFileset 
  119.         return
  120.     } elseif {$f == "Calculator Example"} {
  121.         # Calculator Example.
  122.         calculator
  123.         insertText "1\r1"
  124.         binop +
  125.         insertText "\r1\r1"
  126.         binop +
  127.         insertText "4.2"
  128.         binop *
  129.         return
  130.     } elseif {$f == "Changes Example"} {
  131.         # Changes Example.
  132.         edit -r -c [file join $HOME Help "Changes - Alpha"]
  133.         return
  134.     } elseif {$f == "Compare Example"} {
  135.         # Compare Example.
  136.         edit -r -c [file join $HOME "Mode Examples" Tcl-Example.tcl]
  137.         edit -r -c [file join $HOME Tcl Modes tclMode.tcl]
  138.         compare::windows 
  139.         return
  140.     } elseif {$f == "Eudora Example"} {
  141.         # Eudora Example.
  142.         mailNewMsg ;
  143.         insertText "cupright@princeton.edu" ; nextLine ; endOfLine ;
  144.         insertText "Thanks!" ; nextLine ; nextLine ; 
  145.         insertText "\rDear Craig,\r\r" ;
  146.         insertText "Thanks so much for creating the Mode Examples Folder.\r\r" ;
  147.         insertText "Sincerely,\r\r"    
  148.         return
  149.     } elseif {$f == "Filters Example"} {
  150.         # Filters (tutorial) Example.
  151.         set f3 [file join $HOME "Mode Examples" $f2]
  152.         new -n "* Filters Menu Tutorial *" -m Setx -text [file::readAll $f3] -shell 1
  153.         goto [minPos]
  154.         return
  155.     } elseif {$f == "Filters Example.flt"} {
  156.         # Filters (mode) Example.
  157.         edit -r -c [file join $HOME Tcl UserModifications Filters Example.flt]
  158.         goto [minPos]
  159.         return
  160.     } elseif {$f == "Install Example"} {
  161.         # Install Example.
  162.         edit -r -c [file join $HOME "Mode Examples" "Install-Example"]
  163.         return
  164.     } elseif {$f == "ManipCols Example"} {
  165.         # ManipCols Example.
  166.         set f3 [file join $HOME "Mode Examples" $f2]
  167.         new -n "* Manip Cols Tutorial *" -m Setx -text [file::readAll $f3] -shell 1
  168.         setWinInfo tabsize 8
  169.         goto [minPos]
  170.         return
  171.     } elseif {$f == "Shell Example"} {
  172.         # Shell Example.
  173.         shell ; 
  174.         insertText "cd" ;                   Shel::carriageReturn ;
  175.         insertText "ls" ;                   Shel::carriageReturn ;
  176.         insertText "cd Mode Examples" ;     Shel::carriageReturn ;
  177.         insertText "ls -l" ;                Shel::carriageReturn ;
  178.         insertText "version" ;              Shel::carriageReturn
  179.         return
  180.     } elseif {$f == "WWW Example"} {
  181.         # WWW Example.
  182.         wwwParseFile [file join $HOME "HTML Mode Manual" HTMLmanual.html]
  183.         return
  184.     } elseif {![file exists [file join $HOME "Mode Examples" $f2]]} {
  185.         # Special cases done, look for the file defined by "f".
  186.         beep
  187.         message "Sorry, \"$f2\" is not in the Mode Examples folder"
  188.         return
  189.     }
  190.     # File exists, and it's not a special case, so open it in a shell window.
  191.     set f3 [file join $HOME "Mode Examples" $f2]
  192.     set m  [file::whichModeForWin "dummy[file extension $f3]"]
  193.     # Does Alpha know what mode this is?  If not, send an alertnote.
  194.     if {$m == "Text"} {
  195.         alertnote "Alpha doesn't recognize the mode for this example,\
  196.           and will open it in as plain text."    
  197.     }
  198.     new -n "* $m Mode Example *" -m $m -text [file::readAll $f3] -shell 1
  199.     goto [minPos]
  200.     set    t "\r  $m mode example -- "
  201.     append t "  Modify as much as you like ! \r\r"
  202.     append t "  None of the changes you make will affect the actual file.  If you close \r"
  203.     append t "  the window and then click on the hyperlink again, you will start with the \r"
  204.     append t "  same example as before.  This also means that you cannot send this window \r"
  205.     append t "  to other applications -- technically, it doesn't exist as a file. \r\r"
  206.     append t "  Type \"control-?\" or \"control-Help\" to open any available help for $m mode. \r\r"
  207.     # Find out if there's a tutorial available for this mode.
  208.     set f4 [file join ${HOME} Tcl Completions "[modeALike] Tutorial"]
  209.     set files [glob -nocomplain -path $f4 *]
  210.     if {[llength $files] == 1} {
  211.         append t "  $m mode also has a Completions Tutorial in the Config --> Mode Prefs menu.\r\r"
  212.     }
  213.     insertText  $t
  214.     goto [minPos]
  215.     if {$m == "Text"} {
  216.         help::hyperiseEmailAddresses
  217.         help::hyperiseUrls
  218.     }
  219. }
  220.  
  221.  
  222. # Now we call the newly defined proc.
  223. examples::modeExamplesScriptProc $f
  224.  
  225. # Finally, unset "f" for the next round.
  226. catch {unset f}
  227.  
  228.  
  229. # Here's a little menu proc that will add a "Link To Mode Examples" item to 
  230. # the Color menu, in  :Tcl:Menus:colorsMenu.tcl , binding it to control-0 .
  231. # This was used in Mode Examples version 1.x, for Alpha 7.3 help files.
  232.  
  233. # proc linkToModeExample {{path {}} {from {}} {to {}}} {        
  234. #     global HOME
  235. #     if {$from == {}} { set from [getPos] }
  236. #     if {$to == {}} { set to [selEnd] }
  237. #     if {$from == $to} {
  238. #       beep
  239. #       return
  240. #     }
  241. #     
  242. #     if {$path == {}} {
  243. #       set path [getfile "Choose Mode Example:" [file join $HOME "Mode Examples" ""]]
  244. #       # make path relative to Alpha's home folder
  245. #       set qHome [quote::Regfind $HOME]
  246. #       regsub -- "$qHome" $path {$HOME} path
  247. #     }
  248. #     set filename [file tail $path]
  249. #     regsub -all -- {-} $filename { } filename
  250. #     set    cmd   "set f \"$filename\" ; "
  251. #     append cmd   "source \[file join \$HOME \"Mode Examples\" "
  252. #     append cmd   "\"modeExamplesScript.tcl\"\]"
  253. #         
  254. #     text::color $from $to 3
  255. #     text::hyper $from $to $cmd
  256. #     refresh
  257. # }
  258.  
  259. # The Colors Menu should also have this line:  "/0<BlinkToModeExample"
  260.